import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by zhourh on 2018/5/24.
 */
public class TreeNode {
    int val;

    TreeNode left;

    TreeNode right;

    TreeNode(Integer x) {
        if (x != null) {
            val = x;
        }
    }

    public static String treeNodeToString(TreeNode root) {
        if (root == null) {
            return "[]";
        }

        String output = "";
        Queue<TreeNode> nodeQueue = new LinkedList<>();
        nodeQueue.add(root);
        while(!nodeQueue.isEmpty()) {
            TreeNode node = nodeQueue.remove();

            if (node == null) {
                output += "null, ";
                continue;
            }

            output += String.valueOf(node.val) + ", ";
            nodeQueue.add(node.left);
            nodeQueue.add(node.right);
        }
        return "[" + output.substring(0, output.length() - 2) + "]";
    }
}
